<?php
/**
 * Created by JiangJiaCai.
 * User: LongBob
 * Date: 17-9-24
 * Time: 下午9:30
 */

namespace App\Http\Controllers\home;


use App\Http\Controllers\BaseController;
use App\Models\QdcsArticle;
use App\Models\QdcsProject;
use com_jjcbs\lib\ServiceFactory;
use ext\fun\Helper;
use ext\service\ArticleServiceImpl;
use ext\service\ClassServiceImpl;
use ext\service\OrgServiceImpl;
use ext\service\ProjectServiceImpl;

class NewsController extends BaseController
{
    private $articleService = null;
    private $classService = null;

    public function __construct()
    {
        parent::__construct();
        $this->articleService = ServiceFactory::getInstance(ArticleServiceImpl::class);
        $this->classService = ServiceFactory::getInstance(ClassServiceImpl::class);
    }

    public function index(int $cls_id){
        if ( $cls_id == -1){
            // 热门咨询
            $this->model['news_list'] = $this->articleService->getHotListPage($cls_id);
            $this->model['pos'] = '热门咨询';
        }else{
            $this->model['news_list'] = $this->articleService->getPageListByCls($cls_id);
            $this->model['pos'] = $this->classService->getClassPath($cls_id , ' > ');
        }
        $this->model['hotImg'] = $this->articleService->articleDao->getHotOneHasImg();
        $this->model['hotList'] = $this->articleService->articleDao->getHotPageList(8);
        $this->model['cls_id'] = $cls_id;
        $this->model['projectList'] = ServiceFactory::getInstance(ProjectServiceImpl::class)->getAllChildProjectList(29 , 3);
        $this->model['orgRoot'] = ServiceFactory::getInstance(OrgServiceImpl::class)->orgDao->getRoot();
        return view('news_list' , $this->model);
    }

    public function read(int $id){
        $this->model['news'] = $this->articleService->articleDao->getOne(QdcsArticle::class , $id);
        $this->model['pos'] = $this->articleService->getPos($this->model['news']);
        $this->model['cls_id'] = $this->model['news']->cls_id;
        $this->model['aboutList'] = $this->articleService->getAbout($this->model['news']);
        return view('news' , $this->model);
    }
}